class Solution(object):
    def countSegments(self, s):
        """
        :type s: str
        :rtype: int
        """
        count = 0
        s = s.strip()
        while len(s) > 0:
            non_empty_count = 0
            for c in s:
                if c != ' ':
                    non_empty_count += 1
                else:
                    break
            s = s[non_empty_count:]
            count += 1
            s = s.strip()
        return count
